import { createSlice, type PayloadAction } from "@reduxjs/toolkit";

interface AuthState {
    token: string,
    userType: string,
    user_id:string,
    privateChatUser: string,
}

const initialState: AuthState = {
    token: '',
    userType: '',
    user_id:'',
    privateChatUser:'',
}

const authStore = createSlice({
    name: "channel",
    initialState,
    reducers: {
        setToken: (state, action: PayloadAction<string>) => {
            state.token = action.payload;
        },
        setUserType: (state, action: PayloadAction<string>) => {
            state.userType = action.payload;
        },
        setUserId: (state, action: PayloadAction<string>) => {
            state.user_id = action.payload;
        },
        loginOut: (state) => {
            state.token = '';
            state.userType = '';
            state.user_id = '';
        },
        setPrivateChat: (state, action: PayloadAction<string>) => {
            state.privateChatUser = action.payload;
        }
    },
});


const authReducer = authStore.reducer

export const { setToken, setUserType, loginOut, setUserId, setPrivateChat } = authStore.actions
export default authReducer;